package com.baosight.sczx.common.zm.cInterface.cn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * <p>Title: CommonBlock.java</p>
 * <p>Description: 煤质管理公共下拉框对外接口</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author lhx
 * @version 1.0
 * <pre>Histroy:
 *          2016-9-19 10:40:26  李红星  Create
 *</pre>
 */
public class CoalCode {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	private static CoalCode instance=new CoalCode();
	
	@SuppressWarnings("rawtypes")
	private static List<Map> _list;
	
	private CoalCode(){
		initData();
	}
	
	/**
	 * 初始化数据
	 * <p>Function: initData</p>
	 * <p>Description: </p>
	 * <p>return value:void</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-9-19 10:59:31 李红星 create
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void initData() {
		if(_list != null) {
			_list = null;
		}
		_list = new ArrayList<Map>();
		try {
			_list = dao.query("ZMCNMcmodule.queryCoalCode", null);
		} catch (Exception e) {
			System.out.println(CoalCode.class.getName() + "获取所有煤样编码异常：" + e.getMessage());
		}
	}
	
	/**
	 * 选择煤样编码下拉框(如果要获取所有编码，则分站id和status传空即可)
	 * 
	 * @param blockId 要构造的block的id
	 * @param stationId 煤质中心分站id
	 * @param status 记录状态
	 * @return EiBlock
	 * 
	 * @author hongxing
	 * @since 2016-9-19 16:58:13
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public EiBlock getCoalCodeBlock(String blockId,String _display,String _value,String stationId,String status) {
		EiBlock block = new EiBlock(blockId);

		EiColumn EiColumn = new EiColumn(_value);
		EiColumn.setType("C");
		block.addMeta(EiColumn);
		
		EiColumn = new EiColumn(_display);
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> list = new ArrayList<Map>();
		Map<String, String> _map = new HashMap<String, String>();
		_map.put(_display, "");
		_map.put(_value, "");
		list.add(_map);
        
		for(int i = 0; i < _list.size(); i++) {
			Map<String,String> tmpMap=new HashMap<String,String>();
			_map = _list.get(i);
			if(stationId==null || stationId.equals("")||status==null || status.equals("")){
				tmpMap.put(_value, _map.get(_value));
				tmpMap.put(_display, _map.get(_display));
				list.add(tmpMap); 
			}else if(stationId!=null && !stationId.equals("")){
				if(_map.get("fdMyStation").equals(stationId)){
					tmpMap.put(_value, _map.get(_value));
					tmpMap.put(_display, _map.get(_display));
					list.add(tmpMap); 
				}
			}else if(status!=null && !status.equals("")){
				if(_map.get("fdStatus").equals(status)){
					tmpMap.put(_value, _map.get(_value));
					tmpMap.put(_display, _map.get(_display));
					list.add(tmpMap); 
				}
			}else{
				if(_map.get("fdMyStation").equals(stationId) && _map.get("fdStatus").equals(status)){
					tmpMap.put(_value, _map.get(_value));
					tmpMap.put(_display, _map.get(_display));
					list.add(tmpMap); 
				}
			}
		} 
		block.setRows(list);
		return block;
	}
	
	/**
	 * 初始化该类
	 * <p>Function: getInstance</p>
	 * <p>Description:初始化煤样编码类 </p>
	 * <p>return value:InitialData</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-9-19 17:10:52 李红星
	 * </p>
	 *
	 */
	public static CoalCode getInstance(){
		instance=new CoalCode();
		return instance;
	}
}
